// pages/chartere_bus6/select_airport6-9/select_airport6-9.js
var httpUtil = require('../../utils/httpUtil.js');
var util = require('../../utils/util.js');

var app = getApp();
Page({

  data: {
    countryInfo: [],
    hotAirport: ['洛杉矶机场', '旧金山机场', '纽约机场', '夏威夷机场', '达拉斯机场', '西雅图机场'],
    xibuAirport: ['洛杉矶机场', '旧金山机场', '纽约机场', '夏威夷机场', '达拉斯机场', '西雅图机场'],
    curr: 0,
    curr1: 0,
    curr2: -1,

    areaList: [],
    modelList: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    that.getList();
  },
  getList: function() {
    var that = this;
    httpUtil.getHttp("/country/list", {}, function(res) {
      var arr = [];
      var areaList = [];
      if (res != null && res.length != 0) {
        for (var i = 0; i < res.length; i++) {
          arr.push(res[i].countryName);
        }
        areaList = res[0].areaList;
        // if (res[0].areaList != null && res[0].areaList.lenth != 0) {
        //   console.log();
        //   if (res[0].areaList[0].airportList[0] != null && res[0].areaList[0].airportList[0].lenth != 0) {
        //     // res[0].areaList[0].airportList[0].status=1;
        //     // that.setAirport(res[0].areaList[0].airportList[0])
        //   }

        // }
      }
      that.setData({
        modelList: res,
        countryInfo: arr,
        areaList: areaList
      })
    })

  },
  setAirport: function(airport) {
    var pages = getCurrentPages();

    var prevPage = pages[pages.length - 2]; //上一个页面
    prevPage.setData({
      airport: airport
    })
    wx.navigateBack()

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  selCountry: function(e) {
    var that = this;
    this.setData({
      curr: e.currentTarget.dataset.item,
      areaList: that.data.modelList[e.currentTarget.dataset.item].areaList
    })

  },
  selhotAirport: function(e) {
    var that = this;
    var id = e.target.dataset.item;
    var list = that.data.areaList;

    for (var i = 0; i < list.length; i++) {
      console.log(list[i]);

      for (var s = 0; s < list[i].airportList.length; s++) {

        if (list[i].airportList[s].id == id) {
          list[i].airportList[s].status = 1;
          that.setAirport(list[i].airportList[s])
        } else {
          list[i].airportList[s].status = 0;
        }
      }
    }
    this.setData({
      areaList: list
    })
  },
  selxibuAirport: function(e) {
    this.setData({
      curr2: e.currentTarget.dataset.item,
      curr1: -1
    })
  },
  search: function(e) {
    wx.navigateTo({
      url: '../search/search'
    })
  }
})